package com.niodata.dp.core.dblock;

import java.util.Date;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface MysqlLocker {

  @Insert("insert into LOCK_RECORD(NAME,TIME,OWNER) VALUES(#{name},#{time},#{locker})")
  void lock(@Param("name") String name, @Param("time") Date time,
        @Param("locker") String locker);

  @Delete("delete from LOCK_RECORD WHERE NAME=#{name} and OWNER=#{locker}")
  void releaseLock(@Param("name") String name, @Param("locker") String locker);

  @Select("select NAME,TIME,OWNER FROM LOCK_RECORD WHERE NAME=#{lockName}")
  Lock getLock(@Param("lockName") String lockName);
}
